<template>
	<view>
		<top-bar @addMsg="addMsg"></top-bar>
		<search-bar :msgList="msgList" @searchMsg="searchMsg"></search-bar>
		<msg-list-bar @deleteMsg="deleteMsg"  :msgList.sync="msgList"></msg-list-bar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				msgList: [],
			}
		},
		onLoad() {
			this.getMsgList();
			uni.$on("addMsg", msg => {
				this.msgList.push(msg);
			});
		},
		methods: {
			deleteMsg(index){
				this.msgList.splice(index, 1);
				
			},
			searchMsg(msgList){
				this.msgList = msgList;
			},
			getMsgList() {
				this.msgList = [{
						name: "用户1",
						time: "2021-12-23",
						content: "我是消息我是消息我是消息我是消息我是消息我是消息我是消息",
						avatar: "../../../../static/avatar/avatar1.jpeg"
					},
					{
						name: "用户2",
						time: "2021-12-23",
						content: "我是消息我是消息我是消息我是消息我是消息我是消息我是消息",
						avatar: "../../../../static/avatar/avatar2.jpeg"
					},
					{
						name: "用户3",
						time: "2021-12-23",
						content: "我是消息我是消息我是消息我是消息我是消息我是消息我是消息",
						avatar: "../../../../static/avatar/avatar3.jpeg"
					}
				];
	
			},
		}
	}
</script>

<style>
</style>
